﻿using AnesSystem.Models;
using AnesSystem.Services;
using Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AnesSystem.ViewModels
{
    public class WorkScoreRCViewModel : BaseViewModel<WorkScoreRCViewModel>
    {
        #region Variables


        #endregion


        #region Constructor

        #endregion


        #region Properties


        #endregion


        #region 依赖属性


        #endregion


        #region Event


        #endregion


        #region PrivateMethods


        #endregion


        #region Public/ProtectedMethods
        public void CalWorkScore()
        {
            if (PatientLink != null && Constants.OR_STATUS_FLAG_OUT_ROOM.Equals(PatientLink.Application.Detailstatus))
            {
                if (!string.IsNullOrEmpty(PatientLink.AnesthesiaRecord.Mzff))
                {
                    if (PatientLink.AnesthesiaRecord.Mzff.Contains("气管插管全麻"))
                    {
                        if (PatientLink.AnesthesiaRecord.Mzff.Contains("双腔"))
                        {
                            PatientLink.Gongfen.QuanMaShuangQiang = 6;
                        }
                        else
                        {
                            PatientLink.Gongfen.QuanMaDanQiang = 4;
                        }
                    }

                    if (PatientLink.AnesthesiaRecord.Mzff.Contains("非插管全麻"))
                    {
                        PatientLink.Gongfen.FeiChaGuanQuanMa = 4;
                    }

                    if (PatientLink.AnesthesiaRecord.Mzff.Contains("椎管内麻醉"))
                    {
                        if (PatientLink.AnesthesiaRecord.Mzff.Contains("腰硬联合"))
                        {
                            PatientLink.Gongfen.YaoYingLianHe = 4;
                        }
                    }
                    if (PatientLink.AnesthesiaRecord.Mzff.Contains("硬膜外"))
                    {
                        PatientLink.Gongfen.YingMoWai = 3;
                    }
                    if (PatientLink.AnesthesiaRecord.Mzff.Contains("神经阻滞"))
                    {
                        PatientLink.Gongfen.ShenJingZuZhi = 3;
                    }
                    if (PatientLink.AnesthesiaRecord.Mzff.Contains("复合麻醉"))
                    {
                        PatientLink.Gongfen.FuHeMazui = 4;
                    }
                }

                if (PatientLink.AnesthesiaRecord.Dmcc)
                {
                    PatientLink.Gongfen.DongMaiChuanCi = 3;
                }
                if (PatientLink.AnesthesiaRecord.Zxjmcc)
                {
                    PatientLink.Gongfen.ZhongXinJingMaiChuanCi = 3;
                }
                if (PatientLink.AnesthesiaRecord.Csyd)
                {
                    PatientLink.Gongfen.ShuZhongChaoSheng = 3;
                }
                if (PatientLink.AnesthesiaRecord.PCEA || PatientLink.AnesthesiaRecord.PCIA || PatientLink.AnesthesiaRecord.PCNA)
                {
                    PatientLink.Gongfen.ShuHouZhenTong = 1;
                }
                if (PatientLink.AnesthesiaRecord.Xqfx)
                {
                    PatientLink.Gongfen.ShuZhongXueQiFenXi = 1;
                }
                if (!PatientLink.Status.MazuiStartTime.Equals(new DateTime()) && !PatientLink.Status.MazuiEndTime.Equals(new DateTime()))
                {
                    TimeSpan span = PatientLink.Status.MazuiEndTime - PatientLink.Status.MazuiStartTime;
                    double totalMin = span.TotalMinutes;
                    if (totalMin >= 30)
                    {
                        int hour = (int)(totalMin / 60);
                        double mins = totalMin - hour * 60;
                        if (mins >= 30)
                        {
                            hour = hour + 1;
                        }
                        if (!string.IsNullOrEmpty(PatientLink.AnesthesiaRecord.Mzff))
                        {
                            if (PatientLink.AnesthesiaRecord.Mzff.Contains("全麻"))
                            {
                                PatientLink.Gongfen.QuanMaJianCe = hour * 3;
                            }
                            else
                            {
                                PatientLink.Gongfen.FeiQuanMaJianCe = hour * 2;
                            }
                        }
                    }
                }
                List<PatientEventsModel> eventList = OperationDataPool.Instance.CurOperationData.EventDataCacheDic[Constants.ISANES].SearchAllEventExe();
                bool flag = false;
                foreach (var item in eventList)
                {
                    if ("event_11".Equals(item.Code))
                    {
                        flag = true;
                        break;
                    }
                }
                if (flag)
                {
                    PatientLink.Gongfen.QiangJiuQiGuanChaGuan = 3;
                }
                GongFenZhiBiaoRCModel gongFen = PatientLink.Gongfen;
                double total = gongFen.QuanMaShuangQiang + gongFen.QuanMaDanQiang + gongFen.FeiChaGuanQuanMa + gongFen.YaoYingLianHe + gongFen.YingMoWai + gongFen.ShenJingZuZhi + gongFen.FuHeMazui + gongFen.DongMaiChuanCi +
                    gongFen.ZhongXinJingMaiChuanCi + gongFen.ShuZhongChaoSheng + gongFen.ShuZhongXueQiFenXi + gongFen.QiangJiuQiGuanChaGuan + gongFen.ShuHouZhenTong + gongFen.QuanMaJianCe + gongFen.FeiQuanMaJianCe;
                PatientLink.Gongfen.Total = total;
                PatientLinkService.Instance.AddUpdate(PatientLink);

            }
        }

        #endregion


        #region EventHandlers


        #endregion
    }
}
